package com.think.teaching.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.think.teaching.mapper.TrainingCheckPointMapper;
import com.think.teaching.model.TrainingCheckPoint;
import com.think.teaching.service.TrainingCheckPointService;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 实训计分点 服务实现类
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
@Service
public class TrainingCheckPointServiceImpl extends BaseServiceImpl<TrainingCheckPointMapper, TrainingCheckPoint> implements TrainingCheckPointService {

	@Override
	public TrainingCheckPoint AddTrainingCheckPoint(TrainingCheckPoint trainingCheckPoint) {
		if (this.save(trainingCheckPoint)) {
			return trainingCheckPoint;
		}
		return null;
	}

	@Override
	public TrainingCheckPoint UpdateTrainingCheckPoint(TrainingCheckPoint trainingCheckPoint) {
		if (this.updateById(trainingCheckPoint)) {
			return trainingCheckPoint;
		}
		return null;
	}

	@Override
	public TrainingCheckPoint GetTrainingCheckPoint(Integer id) {
		QueryWrapper<TrainingCheckPoint> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id).eq("state", 1).ne("delflag", 1);
		return getOne(queryWrapper);
	}

	@Override
	public TrainingCheckPoint SetTrainingCheckPointState(Integer id,Integer state) {
		UpdateWrapper<TrainingCheckPoint> queryWrapper = new UpdateWrapper<>();
		queryWrapper.eq("id", id).ne("delflag", 1).set("state", state);
		this.update(queryWrapper);
		return getById(id);
	}
	
	
	public List<TrainingCheckPoint> listCheckPointByTrainingId(Integer id,Boolean withoutBan){
		QueryWrapper<TrainingCheckPoint> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("train_id", id).ne("delflag", 1);
		if (withoutBan) {
			queryWrapper.eq("state", 1);
		}
		return list(queryWrapper);
	}

}
